package cn.com.qtgl.apis.builtin.comp.service;

import cn.com.qtgl.apis.builtin.comp.proxy.BuiltinProxy;
import cn.com.qtgl.apis.builtin.model.vo.Department;
import cn.com.qtgl.apis.builtin.model.vo.user.User;
import cn.com.qtgl.apis.builtin.model.vo.userfilter.UserFiltersApiIntact;
import cn.com.qtgl.userfilters.model.pojo.UserFilters;
import cn.melonlib.cores.commons.comp.utils.FilterTools;
import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@Service
public class UserFilterApiService extends ApplicationObjectSupport {


    @Resource
    private BuiltinProxy builtin;

    @Resource
    private FilterTools filterTools;

    public UserFiltersApiIntact intactUserFilters(String userFilters){
        UserFilters userFiltersObj = UserFilters.parseUserFilters(userFilters);
        ExecutorService executorService = Executors.newFixedThreadPool(30);
        userFiltersObj.getUserFilters().stream().flatMap(userFilter -> {
            List<Future> futureList=new ArrayList<>();
            switch (userFilter.getUserFilterType()){
                case POSITION -> {
                    String depCode=userFilter.getTriple().getItems().get(0);

                    if(!Objects.equals(depCode,"*")) {
                        Department department=builtin.departments(filterTools.createFilters().addEq("code", userFilter.getTriple().getItems().get(0)).getConditionsMap())
                                .getEdges().get(0).getNode();

                    }
                }
                default  -> {
                    User user= builtin.users(filterTools.createFilters().addEq("openid",userFilter.getTriple().getItems().get(0)).getConditionsMap())
                            .getEdges().get(0).getNode();
                }
            }
            executorService.submit(()->{

                return "aaa";
            });
            return futureList.stream();
        });

        executorService.shutdown();
        return null;
    }
}
